package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainManager;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * projectName: wokepase1
 *
 * @author: 强力
 * time: 2021/10/16 17:44
 * description:
 */
@Component
@Slf4j
public class PreSenQueuelListener {


    @Autowired
    private FilterChainManager filterChainManager;

@RabbitListener(queues = RabbitMQConstants.TOPIC_PRE_SEND)
    public void  messageHandler(StandardSubmit standardSubmit, Channel channel, Message message){
    log.info("[策略模块] 接受短信数据 接收的短信对象为standardSubmit={}",standardSubmit);

    //调用service,对短信对象进行策略吹
filterChainManager.execute(standardSubmit);

    //对消息进行手动ack
    try {
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    } catch (IOException e) {
        e.printStackTrace();
        log.info("[策略模块] 接受短信数据执行失败,短信对象standardSubmit={}",standardSubmit);

    }

}
}
